package com.changgou.order.service.impl;

import com.changgou.goods.feign.GoodsFeign;
import com.changgou.goods.pojo.Sku;
import com.changgou.order.dao.MyFootMarkMapper;
import com.changgou.order.pojo.MyFootMark;
import com.changgou.order.service.MyFootMarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MyFootMarkServiceImpl implements MyFootMarkService {
    @Autowired
    private MyFootMarkMapper myFootMarkMapper;
    @Autowired
    private GoodsFeign goodsFeign;

    /**
     * 添加足迹
     * @param myFootMark
     */
    @Override
    public void addMyFootMark(MyFootMark myFootMark) {
        myFootMarkMapper.insert(myFootMark);
    }

    /**
     * 我的足迹
     * @param username
     * @return
     */
    @Override
    public List<Sku> findByUsername(String username) {
        List<Long> Ids = myFootMarkMapper.findSkuIds(username);
        ArrayList<Sku> skus = new ArrayList<>();
        for (Long id : Ids) {
            Sku sku = goodsFeign.findById(String.valueOf(id)).getData();
            skus.add(sku);
        }
        return skus;
    }
}
